// ActionScript file

package zakladki.AS3 {

import flash.system.Capabilities;

import mx.collections.*;
import mx.controls.*;
import mx.core.Application;
import mx.core.FlexGlobals;

public class EmissionReductionChangeListener {

    private var energyProductionCombo:ComboBox;
    private var industrialReductionCombo:ComboBox;
    private var transportReductionCombo:ComboBox;

    private var mainApplication:Fossilminator = FlexGlobals.topLevelApplication as Fossilminator;


    public function EmissionReductionChangeListener(energyProductionCombo:ComboBox, industrialReductionCombo:ComboBox, transportReductionCombo:ComboBox) {
        this.energyProductionCombo = energyProductionCombo;
        this.industrialReductionCombo = industrialReductionCombo;
        this.transportReductionCombo = transportReductionCombo;
    }

    public function industrialEmissionChanged(calc:Boolean):void {
        applyChange(calc);
    }

    public function energyProductionChanged(calc:Boolean):void {
        applyChange(calc);
    }

    public function transportEmissionChanged(calc:Boolean):void {
        applyChange(calc);
    }

    private function applyChange(calc:Boolean):void {
        if (calc) {
            doApplyChange();
        }
    }

    private function doApplyChange():void {
        updatePerson(createSelectData());
        mainApplication.calculate();
    }

    private function createSelectData():EmissionSelectedData {
        return new EmissionSelectedData(getComboData(energyProductionCombo),getComboData(industrialReductionCombo),getComboData(transportReductionCombo));
    }

    private function getComboData(combo:ComboBox):int {
        return combo.selectedItem.data;
    }

    private function updatePerson(emissionData:EmissionSelectedData):void {
        mainApplication.updateYourEmission(emissionData);
    }


}
}

		
